package com.mrx.xfriendship.service;

import com.mrx.xfriendship.converter.UserConverter;
import com.mrx.xfriendship.converter.UserDetailConverter;
import com.mrx.xfriendship.dao.PhotoWallMapper;
import com.mrx.xfriendship.dao.UserDetailMapper;
import com.mrx.xfriendship.dao.UserMapper;
import com.mrx.xfriendship.model.dto.UserDetailDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Mr.X
 * @since 2023-01-14 10:12
 */
@Service
@DubboService
public class UserDetailServiceImpl implements IUserDetailService {

    @Resource
    private UserDetailMapper userDetailMapper;

    @Resource
    private UserDetailConverter userDetailConverter;

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserConverter userConverter;

    @Resource
    private PhotoWallMapper photoWallMapper;

    @Override
    public UserDetailDTO getUserDetail(Integer userId) {
        UserDetailDTO userDetailDTO = userDetailConverter.toDTO(userDetailMapper.selectByUserId(userId));
        userDetailDTO.setUser(userConverter.toDTO(userMapper.selectByPrimaryKey(userId)));
        userDetailDTO.setPhotos(userDetailConverter.toPreviewPhotos(photoWallMapper.selectByUserId(userId)));
        return userDetailDTO;
    }

}
